package com.koala.design.watch;

import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

/**
 * 观察链
 *
 * @author yantingrui
 * @date 2022/8/15   10:10
 */
@Data
public class Subject {
    private List<Watcher> watchers = Lists.newLinkedList();
    private String name;
    private String todo;

    public Subject(String name) {
        this.name = name;
    }

    public void setTodo(String todo) {
        this.todo = todo;
        for (Watcher watcher : watchers) {
            watcher.update(this);
        }
    }

    public void attach(Watcher watcher) {
        this.watchers.add(watcher);
    }
}
